package com.iespring.controller.app.coupon;

import com.iespring.bean.app.coupon.bo.WxCouponPageBo;
import com.iespring.bean.common.BaseRespVo;
import com.iespring.service.app.coupon.WxCouponService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * Auth: 杨宇健
 * Time: 2023/1/1 18:56
 * Description:
 **/
@RequestMapping("wx/coupon")
@RestController
public class WxCouponController {
    @Resource
    WxCouponService wxCouponService;
    @GetMapping("mylist")
    public BaseRespVo mylist(WxCouponPageBo pageInfo) {
        BaseRespVo respVo = wxCouponService.myList(pageInfo);
        return respVo;
        //return null;
    }

    @GetMapping("list")
    public BaseRespVo list(WxCouponPageBo pageInfo) {
        BaseRespVo respVo = wxCouponService.list(pageInfo);
        return respVo;
        //return null;
    }

    @PostMapping("receive")
    public BaseRespVo receive(@RequestBody Map<String,Integer> map){
        Integer couponId = map.get("couponId");
        if (couponId == null) {
            return BaseRespVo.error("参数不对", 500);
        }
        BaseRespVo respVo =  wxCouponService.receive(couponId);
        return respVo;
    }

    //兑换优惠券
    @PostMapping("exchange")
    public BaseRespVo exchange(@RequestBody Map<String,String> map){
        String code = map.get("code");
        if (code == null) {
            return BaseRespVo.error("参数不对", 500);
        }
        BaseRespVo respVo =  wxCouponService.exchange(code);
        return respVo;
    }

    //购买时选择的优惠券
    @GetMapping("selectlist")
    public BaseRespVo selectList(Integer grouponRulesId, Integer cartId){
        BaseRespVo respVo =  wxCouponService.selectList(cartId, grouponRulesId);
        return respVo;
    }

}
